/*
 * MIT License
 *
 * Copyright (c) 2020 wen.gu <454727014@qq.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/***************************************************************************
 * Name: mp_types.h
 *
 * Purpose: the base data type define for micro player
 *
 * Developer:
 *   wen.gu , 2018-09-03
 *
 * TODO: 
 *
 ***************************************************************************/
#ifndef __MP_TYPES_H__
#define __MP_TYPES_H__

/******************************************************************************
**    INCLUDES
******************************************************************************/
#include <stdint.h>
#include <mutex>

/******************************************************************************
**    MACROS
******************************************************************************/


#ifdef __cplusplus
#define MP_EXTERN_C extern "C"
#else
#define MP_EXTERN_C 
#endif


#if defined(_MSC_VER) /** !!!for visual studio */
////////////////////////////////////////////////////////////////////////////
/** compat the keyword 'inline' */
#if (_MSC_VER > 1200) && !defined (__cplusplus)
#define inline    _inline  /** to compat keyword 'inline' */
#endif

#if defined (MP_DLL_EXPORT)
#define MP_API_EXPORT __declspec(dllexport)
#else
#define MP_API_EXPORT

#endif
#else /** for other toolchain */
#define MP_API_EXPORT 
#endif

/** general api decorate macro */
#define MP_API MP_API_EXPORT /**c++ api */

#define MP_API_C MP_EXTERN_C MP_API_EXPORT /** c api */

/** general class decorate macro*/
#define MP_CLASS MP_API_EXPORT

/** general global variable decorate macro(for external reference ) */
#define MP_VAR  extern MP_API_EXPORT 

/** general const global variable decorate macro(for external reference ) */
#define MP_CVAR MP_VAR const 



 // Conditional NORETURN attribute on the throw functions would:
 // a) suppress false positives from static code analysis
 // b) possibly improve optimization opportunities.
#if !defined(MP_NO_RETURN)
#if defined(_MSC_VER)
#define MP_NO_RETURN __declspec(noreturn)
#elif defined(__GNUC__)
#define MP_NO_RETURN __attribute__((__noreturn__))
#else
#define MP_NO_RETURN
#endif
#endif

//fourcc macro define
#define GFCC(a, b, c, d)    (((uint32_t)a) | (((uint32_t)b) << 8) |\
                            (((uint32_t)c) << 16) | (((uint32_t)d) << 24))




/**for error adaption */
#define MPError eMPError

#define MP_OK                         eMPError::OK
#define MP_FAIL                       eMPError::Fail
#define MP_ErrorBadParameter          eMPError::BadParameter
#define MP_ErrorNoInit                eMPError::NoInit
#define MP_ErrorEof                   eMPError::Eof
#define MP_ErrorNotImplemented        eMPError::NotImplemented
#define MP_ErrorNotFound              eMPError::NotFound
#define MP_ErrorUndefined             eMPError::Undefined
#define MP_ErrorInvalidName           eMPError::InvalidName
#define MP_ErrorInsufficientResources eMPError::InsufficientResources
#define MP_ErrorInvalidStatus         eMPError::InvalidStatus
#define MP_ErrorOutOfRange            eMPError::OutOfRange
#define MP_ErrorUnsupportedType       eMPError::UnsupportedType
#define MP_ErrorTimeout               eMPError::Timeout
/******************************************************************************
**    TYPE DEFINITIONS
******************************************************************************/
enum class eMPError : uint32_t
{
    /** define base error */
    OK = 0,
    Fail,

    /** One or more parameters were invalid */
    BadParameter,
    /** not initialized */
    NoInit,

    /** EOF  error */
    Eof,

    /** The function is not implemented */
    NotImplemented,

    /** not found the target */
    NotFound,

    /** There was an error, but the cause of the error could not be determined */
    Undefined,

    /** The name string is invalid */
    InvalidName,

    /** There were insufficient resources to perform the requested operation */
    InsufficientResources,

    /** invalid status */
    InvalidStatus,

    /** some exception about out of range */
    OutOfRange,

    /** there was unsupported type */
    UnsupportedType,

    /** there was time out */
    Timeout,
};


/** log level */
/** auto middleware framework log level */
enum eMPLogLevel
{/** MPL: auto middleware framework log */
    MPL_LevelError = 0,
    MPL_LevelWarning,
    MPL_LevelInfo,
    MPL_LevelDebug,
};


/** auto mutex lock */
typedef std::unique_lock <std::mutex> AutoLock;
/******************************************************************************
**    CLASSES/FUNCTIONS DEFINITIONS
******************************************************************************/

MP_API const char* MPError2Str(eMPError err);

#endif /** !__MP_TYPES_H__*/


 
